//
//  HomeViewController.swift
//  navigation
//
//  Created by tuwan on 2018/1/27.
//  Copyright © 2018年 czmc .Inc. All rights reserved.
//

import UIKit
private let mTitleHeight:CGFloat = 50
class HomeViewController: UIViewController {
    
    private lazy var indicator:ViewPagerIndicator = {
         let frame = CGRect(origin:CGPoint.init(x: 0, y: mStatusbarHeight+mNavibarHeight),size: CGSize(width:mScreenWidth,height:mTitleHeight))
        return ViewPagerIndicator(frame: frame,titles:["one","two","three","four"])
        
    }()
    private lazy var viewPager :ViewPager = {
        var childs = [UIViewController]()
        for  _ in 0...3 {
            let child =  UIViewController()
            child.view.backgroundColor = UIColor.randomColor;
            childs.append(child)
        }
        let height = mScreenHeight - mStatusbarHeight - mTitleHeight - mNavibarHeight;
        let frame = CGRect(x:0,y:mStatusbarHeight+mNavibarHeight+mTitleHeight,width:mScreenWidth,height:height);
        return ViewPager(frame:frame,childVcs:childs,parentVc:self)
    }()
    
    
    override func viewDidLoad() {
        setUI()
    }
    
}
//UI相关
extension HomeViewController{
    func setUI(){
        setUpNavigation()
        indicator.setViewPagerIndicatorDelegate(delegate: viewPager)
        self.view.addSubview(indicator)
        self.view.addSubview(viewPager)
    }
    private func setUpNavigation(){
        let item = UIBarButtonItem(title: "刷新", style: .plain, target: self, action: nil)
        self.navigationItem.leftBarButtonItem = item
        let rightItem = UIBarButtonItem(title: "按钮1", style: .plain, target: self, action: nil)
        let rightItem2 = UIBarButtonItem(title: "按钮2", style: .plain, target: self, action: nil)
        self.navigationItem.rightBarButtonItems = [rightItem,rightItem2]
    }
 
}

